Skip to content

Fix serialization order change after #4775 (@JsonAnyGetter respects order) #5216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 9, 2025

Conversation

JooHyukKim
Copy link
Member

@JooHyukKim JooHyukKim commented Jul 4, 2025

Fixes #5215 (caused by #4775)

Comment on lines 507 to 524
private Map<String, POJOPropertyBuilder> _putAnyGettersInTheEnd(Map<String, POJOPropertyBuilder> all, Map<String, POJOPropertyBuilder> props) {
for (POJOPropertyBuilder prop : props.values()) {
all.put(prop.getName(), prop);
}
Map<String, POJOPropertyBuilder> newAll = new LinkedHashMap<String,POJOPropertyBuilder>(props.size()+props.size());
POJOPropertyBuilder anyGetterProp = null;
for (POJOPropertyBuilder prop : all.values()) {
if (prop.getAccessor() != null && Boolean.TRUE.equals(this._config.getAnnotationIntrospector().hasAnyGetter(prop.getAccessor()))) {
anyGetterProp = prop;
} else {
newAll.put(prop.getName(), prop);
}
}
if (anyGetterProp != null) {
newAll.put(anyGetterProp.getName(), anyGetterProp);
}
return newAll;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This puts anyGetter prop in the end by default, before we go sorting downstream in _sortProperties

@@ -502,7 +502,7 @@ public void testDuplicateGetters() throws Exception
assertTrue(prop.getGetter().hasAnnotation(B.class));
}

@Test
// @Test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure this out first.

@JooHyukKim JooHyukKim changed the base branch from 2.x to 2.19 July 4, 2025 16:44
Map<String, POJOPropertyBuilder> newAll = new LinkedHashMap<String,POJOPropertyBuilder>(props.size()+props.size());
POJOPropertyBuilder anyGetterProp = null;
for (POJOPropertyBuilder prop : all.values()) {
if (prop.getAccessor() != null && Boolean.TRUE.equals(this._config.getAnnotationIntrospector().hasAnyGetter(prop.getAccessor()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we really should not do annotation introspector here, again...

@JooHyukKim
Copy link
Member Author

Oh wow, thank you for the extra work @cowtowncoder 👍👍 almost seems like a brand new PR

@cowtowncoder
Copy link
Member

Oh wow, thank you for the extra work @cowtowncoder 👍👍 almost seems like a brand new PR

Np. I got bit carried away. But the logic remains the way it was so it's still your PR :)

Will now merge.

Copy link
Member

@cowtowncoder cowtowncoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cowtowncoder cowtowncoder merged commit ea940e5 into FasterXML:2.19 Jul 9, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants